home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performPolyGridUV.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  9.7 KB  |  426 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. // Copyright (C) 1997-2002 Alias|Wavefront,
  18. // a division of Silicon Graphics Limited.
  19. //
  20. // The information in this file is provided for the exclusive use of the
  21. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  22. // and incorporate this code into other products for purposes authorized
  23. // by the Alias|Wavefront license agreement, without fee.
  24. //
  25. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  26. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  27. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  28. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  29. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  30. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  31. // PERFORMANCE OF THIS SOFTWARE.
  32. //
  33. // Alias|Wavefront Script File
  34. // MODIFY THIS AT YOUR OWN RISK
  35. //
  36. // adapted from cpam's polyGridUVWin.mel
  37. //
  38. // creates UI for polyGridUV.mel command
  39.  
  40. //
  41. //  Procedure Name:
  42. //      setOptionVars
  43. //
  44. //  Description:
  45. //        Initialize the option values.
  46. //
  47. //  Input Arguments:
  48. //        Whether to set the options to default values.
  49. //
  50. //  Return Value:
  51. //      None.
  52. //
  53. proc setOptionVars(int $forceFactorySettings)
  54. {
  55.     // U
  56.     //
  57.     if ($forceFactorySettings || !`optionVar -exists polyGridUVValueU`) {
  58.         optionVar -intValue polyGridUVValueU 256;
  59.     }    
  60.  
  61.     // V
  62.     //
  63.     if ($forceFactorySettings || !`optionVar -exists polyGridUVValueV`) {
  64.         optionVar -intValue polyGridUVValueV 256;
  65.     }    
  66.  
  67.     // Pixel
  68.     //
  69.     if ($forceFactorySettings || !`optionVar -exists polyGridUVValuePixel`) {
  70.         optionVar -intValue polyGridUVValuePixel 1;
  71.     }
  72. }
  73.  
  74. //
  75. //  Procedure Name:
  76. //      polyGridUVSetup
  77. //
  78. //  Description:
  79. //        Update the state of the option box UI to reflect the option values.
  80. //
  81. //  Input Arguments:
  82. //      parent               - Top level parent layout of the option box UI.
  83. //                             Required so that UI object names can be 
  84. //                             successfully resolved.
  85. //
  86. //        forceFactorySettings - Whether the option values should be set to
  87. //                             default values.
  88. //
  89. //  Return Value:
  90. //      None.
  91. //
  92. global proc polyGridUVSetup(string $parent, int $forceFactorySettings)
  93. {
  94.     //    Retrieve the option settings
  95.     //
  96.     setOptionVars($forceFactorySettings);
  97.  
  98.     setParent $parent;
  99.  
  100.     //    Query the optionVar's and set the values into the controls.
  101.     
  102.     // U
  103.     //
  104.     intSliderGrp -edit
  105.         -value `optionVar -query polyGridUVValueU`
  106.         ugrid;
  107.  
  108.     // V
  109.     //
  110.     intSliderGrp -edit
  111.         -value `optionVar -query polyGridUVValueV`
  112.         vgrid;
  113.  
  114.     // Pixel
  115.     //
  116.     radioButtonGrp -edit
  117.         -select `optionVar -query polyGridUVValuePixel`
  118.         snap;
  119. }
  120.  
  121.  
  122. //
  123. //  Procedure Name:
  124. //      polyGridUVCallback
  125. //
  126. //  Description:
  127. //        Update the option values with the current state of the option box UI.
  128. //
  129. //  Input Arguments:
  130. //      parent - Top level parent layout of the option box UI.  Required so
  131. //               that UI object names can be successfully resolved.
  132. //
  133. //        doIt   - Whether the command should execute.
  134. //
  135. //  Return Value:
  136. //      None.
  137. //
  138. global proc polyGridUVCallback(string $parent, int $doIt)
  139. {
  140.     setParent $parent;
  141.  
  142.     //    Set the optionVar's from the control values, and then
  143.     //    perform the command.
  144.  
  145.     // U
  146.     //
  147.     optionVar -intValue polyGridUVValueU 
  148.         `intSliderGrp -query -value ugrid`;
  149.  
  150.     // V
  151.     //
  152.     optionVar -intValue polyGridUVValueV 
  153.         `intSliderGrp -query -value vgrid`;
  154.  
  155.     // Pixel
  156.     //
  157.     optionVar -intValue polyGridUVValuePixel 
  158.         (`radioButtonGrp -query -select snap` - 1);
  159.  
  160.  
  161.     if ($doIt) {
  162.         performPolyGridUV 0; 
  163.         addToRecentCommandQueue "performPolyGridUV 0" "PolyGridUV";
  164.     }
  165. }
  166.  
  167. //
  168. //  Procedure Name:
  169. //      changePreset
  170. //
  171. //  Description:
  172. //        Helper procedure which sets the slider values to match the
  173. //        item selected from the mapSizePreset menu group.
  174. //
  175. //  Input Arguments:
  176. //      None.
  177. //
  178. //  Return Value:
  179. //      None.
  180. //
  181. global proc performPolyGridUV_changePreset(){
  182.     int $presets[] = {0, 0, 1024, 512, 256, 128, 64, 32, 16};
  183.     int $selectedItem = `optionMenuGrp -query -select mapSizePreset`;
  184.     intSliderGrp -edit -value $presets[$selectedItem] ugrid;
  185.     intSliderGrp -edit -value $presets[$selectedItem] vgrid;
  186.  
  187. }
  188.  
  189.  
  190. //
  191. //  Procedure Name:
  192. //      polyGridUVOptions
  193. //
  194. //  Description:
  195. //        Construct the option box UI.  Involves accessing the standard option
  196. //        box and customizing the UI accordingly.
  197. //
  198. //  Input Arguments:
  199. //      None.
  200. //
  201. //  Return Value:
  202. //      None.
  203. //
  204. proc polyGridUVOptions()
  205. {
  206.     //    Name of the command for this option box.
  207.     //
  208.     string $commandName = "polyGridUV";
  209.  
  210.     //    Build the option box actions.
  211.     //
  212.     string $callback = ($commandName + "Callback");
  213.     string $setup = ($commandName + "Setup");
  214.  
  215.     //    Get the option box.
  216.     //
  217.     string $layout = getOptionBox();
  218.     setParent $layout;
  219.     
  220.     //    Pass the command name to the option box.
  221.     //
  222.     setOptionBoxCommandName($commandName);
  223.     
  224.     //    Activate the default UI template.
  225.     //
  226.     setUITemplate -pushTemplate DefaultTemplate;
  227.  
  228.     //    Turn on the wait cursor.
  229.     //
  230.     waitCursor -state 1;
  231.  
  232.     tabLayout -scr true -tv false;
  233.     string $parent = `columnLayout -adjustableColumn 1`;
  234.     
  235.     optionMenuGrp -l "Map Size Presets" 
  236.         -cc "performPolyGridUV_changePreset"
  237.         mapSizePreset;
  238.  
  239.     menuItem -l " Custom/Non Square";
  240.     menuItem -l "1024 Map";
  241.     menuItem -l " 512 Map";
  242.     menuItem -l " 256 Map";
  243.     menuItem -l " 128 Map";
  244.     menuItem -l "  64 Map";
  245.     menuItem -l "  32 Map";
  246.     menuItem -l "  16 Map";
  247.  
  248.     intSliderGrp 
  249.         -label "Grid U"
  250.         -min 1
  251.         -max 1024
  252.         -f 1
  253.         -fmn 1
  254.         -fmx 1024
  255.         -cc "optionMenuGrp -edit -select 1 mapSizePreset;"
  256.         ugrid;
  257.  
  258.     intSliderGrp
  259.         -label "Grid V"
  260.         -min 1
  261.         -max 1024
  262.         -f 1
  263.         -fmn 1
  264.         -fmx 1024
  265.         -cc "optionMenuGrp -edit -select 1 mapSizePreset;"
  266.         vgrid;
  267.  
  268.     radioButtonGrp -numberOfRadioButtons 2
  269.         -label "Move UVs to" -labelArray2 "Pixel Border" "Pixel Center"
  270.         snap;
  271.  
  272.     //    Turn off the wait cursor.
  273.     //
  274.     waitCursor -state 0;
  275.     
  276.     //    Deactivate the default UI template.
  277.     //
  278.     setUITemplate -popTemplate;
  279.  
  280.     //    'Apply' button.
  281.     //
  282.     string $applyBtn = getOptionBoxApplyBtn();
  283.     button -edit
  284.         -label "Apply and Close"
  285.         -command ($callback + " " + $parent + " " + 1)
  286.         $applyBtn;
  287.  
  288.     //    'Save' button.
  289.     //
  290.     string $saveBtn = getOptionBoxSaveBtn();
  291.     button -edit 
  292.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  293.         $saveBtn;
  294.  
  295.     //    'Reset' button.
  296.     //
  297.     string $resetBtn = getOptionBoxResetBtn();
  298.     button -edit 
  299.         -command ($setup + " " + $parent + " " + 1)
  300.         $resetBtn;
  301.  
  302.     //    Set the option box title.
  303.     //
  304.     setOptionBoxTitle("Poly Grid UV Options");
  305.  
  306.     //    Customize the 'Help' menu item text.
  307.     //
  308.     setOptionBoxHelpTag( "PolyGridUV" );
  309.  
  310.     //    Set the current values of the option box.
  311.     //
  312.     eval (($setup + " " + $parent + " " + 0));    
  313.     
  314.     //    Show the option box.
  315.     //
  316.     showOptionBox();
  317. }
  318.  
  319. //
  320. //  Procedure Name:
  321. //      polyGridUVHelp
  322. //
  323. //  Description:
  324. //        Return a short description about this command.
  325. //
  326. //  Input Arguments:
  327. //      None.
  328. //
  329. //  Return Value:
  330. //      string.
  331. //
  332. proc string polyGridUVHelp()
  333. {
  334.     return 
  335.     "  Command: polyGridUV - snap selected UVs to user specified grid.\n" +
  336.     "Selection: UVs.";    
  337. }
  338.  
  339. //
  340. //  Procedure Name:
  341. //      assembleCmd
  342. //
  343. //  Description:
  344. //        Construct the command that will apply the option box values.
  345. //
  346. //  Input Arguments:
  347. //      None.
  348. //
  349. //  Return Value:
  350. //      string.
  351. //
  352. proc string assembleCmd()
  353. {
  354.     setOptionVars(false);
  355.  
  356.     string $cmd = "polyGridUV" + " " + 
  357.         `optionVar -query polyGridUVValueU` + " " +
  358.         `optionVar -query polyGridUVValueV` + " " + 
  359.         `optionVar -query polyGridUVValuePixel`;
  360.         
  361.     return $cmd;
  362. }
  363.  
  364. //
  365. //  Procedure Name:
  366. //      performPolyGridUV
  367. //
  368. //  Description:
  369. //        Perform the polyGridUV command using the corresponding 
  370. //        option values.  This procedure will also show the option box
  371. //        window if necessary as well as construct the command string
  372. //        that will invoke the polyGridUV command with the current
  373. //        option box values.
  374. //
  375. //  Input Arguments:
  376. //      0 - Execute the command.
  377. //      1 - Show the option box dialog.
  378. //      2 - Return the command.
  379. //
  380. //  Return Value:
  381. //      string.
  382. //
  383. global proc string performPolyGridUV(int $action)
  384. {
  385.     string $cmd = "";
  386.  
  387.     switch ($action) {
  388.  
  389.         //    Execute the command.
  390.         //
  391.         case 0:
  392.             //    Retrieve the option settings
  393.             //
  394.             setOptionVars(false);
  395.  
  396.             //    Get the command.
  397.             //
  398.             $cmd = `assembleCmd`;
  399.  
  400.             //    Execute the command with the option settings.
  401.             //
  402.             evalEcho($cmd);
  403.  
  404.             break;
  405.  
  406.         //    Show the option box.
  407.         //
  408.         case 1:
  409.             polyGridUVOptions;
  410.             break;
  411.  
  412.         //    Return the command string.
  413.         //
  414.         case 2:
  415.             //    Retrieve the option settings.
  416.             //
  417.             setOptionVars (false);
  418.  
  419.             //    Get the command.
  420.             //
  421.             $cmd = `assembleCmd`;
  422.             break;
  423.     }
  424.     return $cmd;
  425. }
  426.